import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/2 21:32
 * @description 假设为行升序，列降序，那么从左上角或右下角
 */
public class Solution2 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        int[][] mat = {{18, 21, 23, 226, 30}, {10, 13, 14, 17, 24}, {3, 6, 9, 16, 22}, {2, 5, 6, 12, 19}, {1, 4, 7, 11, 15}};
        solution2.searchMatrix(mat, 5);
    }

    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;
        int x = 0, y = 0;
        while (x < m && y < n) {
            int t = matrix[x][y];
            if (t == target) {
                return true;
            } else if (t > target) {
                x++;
            } else {
                y++;
            }
        }

        return false;
    }
}
